How to Pass or Access Command-line Arguments in C#?
How to Pass or Access Command-line Arguments in C#?
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Ravi Vishwakarma
10-Jun-2024In C#, you can pass command-line arguments to your application and access them within the Main method. The Main method can be defined to accept an array of strings as its parameter, which represents the command-line arguments.
Example of Passing and Accessing Command-line Arguments
Here's a simple example demonstrating how to pass and access command-line arguments in a C# console application:
Running the Application with Command-line Arguments
To run the application with command-line arguments, you can use a terminal or command prompt. Navigate to the directory where your compiled executable is located and run it with arguments:
Or if you are running the compiled executable directly:
Handling Command-line Arguments in Visual Studio
If you are using Visual Studio, you can set command-line arguments in the project properties:
Detailed Explanation
Output :